import 'dart:io';


import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';

import 'i_router.dart';
import 'local_storage.dart';
import 'main.dart';


class ProtocolDialog {
  static showProtocolDialog(BuildContext context) {
    showDialog(
        context: context,
        barrierColor: Colors.black.withOpacity(0.5),
        barrierDismissible: false,
        builder: (BuildContext buildContext) {
          return WillPopScope(
            onWillPop: () async => false,
            child: Center(
              child: Container(
                width: 280,
                decoration: BoxDecoration(
                  borderRadius: BorderRadius.circular(8),
                  color: Colors.white,
                ),
                child: Column(
                  mainAxisSize: MainAxisSize.min,
                  children: [
                    Container(
                      width: double.infinity,
                      alignment: Alignment.center,
                      padding: const EdgeInsets.only(
                        top: 26,
                      ),
                      child: const Text(
                        textAlign: TextAlign.center,
                        'Service Agreement and Privacy Policy',
                        style: TextStyle(
                            color: Color(0xFF070E1F),
                            fontSize: 18,
                            fontWeight: FontWeight.w600),
                      ),
                    ),
                    Container(
                      width: double.infinity,
                      alignment: Alignment.centerLeft,
                      padding:
                          const EdgeInsets.only(top: 10, left: 20, right: 20),
                      child: RichText(
                        text: TextSpan(children: [
                          const TextSpan(
                            text:
                                "       Please be sure to carefully read and fully understand the terms of the \"Service Agreement\" and \"Privacy Policy\", including but not limited to: In order to better provide you with services, we need to collect your device identification, operation logs and other information for analysis, Optimize application performance. \n You can read ",
                            style: TextStyle(
                              fontSize: 14,
                              color: Color(0xFF070E1F),
                            ),
                          ),
                          TextSpan(
                            text: "《User Services Agreement》",
                            style: const TextStyle(
                              fontSize: 14,
                              color: Color(0xFF004AFF),
                            ),
                            recognizer: TapGestureRecognizer()
                              ..onTap = () {
                                // PageRouter.toWebPage(context,
                                //     '${Global.hostApi}/agreement.html');
                              },
                          ),
                          const TextSpan(
                            text: "Add",
                            style: TextStyle(
                              fontSize: 14,
                              color: Color(0xFF070E1F),
                            ),
                          ),
                          TextSpan(
                            text: "《Privacy Policy》",
                            style: const TextStyle(
                              fontSize: 14,
                              color: Color(0xFF004AFF),
                            ),
                            recognizer: TapGestureRecognizer()
                              ..onTap = () {
                                // PageRouter.toWebPage(context,
                                //     '${Global.hostApi}/privacypolicy.html');
                              },
                          ),
                          const TextSpan(
                            text: "Learn more. If you agree, please click the button below to start receiving our services。",
                            style: TextStyle(
                              fontSize: 14,
                              color: Color(0xFF070E1F),
                            ),
                          ),
                        ]),
                      ),
                    ),
                    Container(
                      width: double.infinity,
                      padding: EdgeInsets.only(right: 20, left: 20),
                      child: Row(
                        mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                        children: [
                          GestureDetector(
                            onTap: () => exit(0),
                            child: Container(
                              padding: EdgeInsets.all(20),
                              child: const Text(
                                textAlign: TextAlign.center,
                                'Don\'t agree',
                                style: TextStyle(
                                    color: Color(0x80070E1F), fontSize: 14),
                              ),
                            ),
                          ),
                          GestureDetector(
                            onTap: () async {
                              Navigator.pop(context);
                              Navigator.pushAndRemoveUntil(
                                  context,
                                  MaterialPageRoute(
                                      builder: (context) =>
                                           MyHomePage()),
                                  (route) => false);
                              await LocalStorage.initSP();
                              LocalStorage.save('isInstalled', '1');
                            },
                            child: Container(
                              padding: EdgeInsets.all(20),
                              child: const Text(
                                textAlign: TextAlign.center,
                                'I see',
                                style: TextStyle(
                                    color: Color(0xFF070E1F), fontSize: 14),
                              ),
                            ),
                          )
                        ],
                      ),
                    )
                  ],
                ),
              ),
            ),
          );
        });
  }
}
